package com.zzb.projectfactory.framework.role.dao;

import com.zzb.projectfactory.framework.role.dao.jpa.SysRoleRepository;
import com.zzb.projectfactory.framework.role.dao.mybatis.SysRoleMapper;
import com.zzb.projectfactory.framework.role.entity.SysRole;
import com.zzb.projectfactory.framework.common.BaseDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 角色表 Dao接口
 */
@Repository
public class SysRoleDAO extends BaseDAO<SysRole,SysRoleRepository> {
    @Autowired
    private SysRoleRepository sysRoleRepository;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public SysRoleRepository getRepository() { return sysRoleRepository; }

    public List<SysRole> findByUserId(String userId) {
        return sysRoleMapper.findByUserId(userId);
    }

    /**
     * 通过角色码查询角色 */
    public SysRole findByRoleCode(String roleCode){
        return getRepository().findTopByRoleCodeOrderByCreateTimeDesc(roleCode);
    }

}
